852. 山脉数组的峰顶索引
为保证权益,题目请参考 852. 山脉数组的峰顶索引(From LeetCode).
解决方案1
Python
python
from typing import List
class Solution:
def peakIndexInMountainArray(self, arr: List[int]) -> int:
for i in range(1, len(arr) - 1):
if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
return i
if __name__ == "__main__":
so = Solution()
print(so.peakIndexInMountainArray([0, 2, 1, 0]))
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13